<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreatePledgePropertyBuildings extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('pledge_property_buildings', function (Blueprint $table) {
            $table->id()->from(config('migration.from'));

            $table->text('address')->nullable()->comment('Адрес');

            $table->enum('number_type', ['cadastral', 'conditional', 'inventory'])->comment('Тип номера')->nullable();
            $table->string('number')->nullable()->comment('Номер');

            $table->string('total_area')->nullable()->comment('Общая площадь');

            $table->jsonb('plans')->default(json_encode([]))->comment('Технический план');
            $table->index('plans', null, 'gin');

            $table->string('floors_number')->nullable()->comment('Этажность');

            $table->text('object_composition')->nullable()->comment('Состав объекта');

            $table->text('other_information')->nullable()->comment('Иные сведения');

            $table->jsonb('documents')->default(json_encode([]))->comment('Иные документы');
            $table->index('documents', null, 'gin');

            $table->jsonb('images')->default(json_encode([]))->comment('Фото залога');
            $table->index('images', null, 'gin');

            $table->nullableMorphs('contract');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('pledge_property_buildings');
    }
}
